#!/bin/bash

echo "===================================="
echo "网络配置备份平台启动脚本"
echo "===================================="
echo ""

echo "[1/3] 检查Python环境..."
if ! command -v python3 &> /dev/null; then
    echo "错误: 未找到Python，请先安装Python 3.8+"
    exit 1
fi
python3 --version
echo ""

echo "[2/3] 检查依赖..."
if ! python3 -c "import fastapi" 2>/dev/null; then
    echo "正在安装依赖..."
    pip3 install -r requirements.txt
fi
echo ""

echo "[3/3] 启动应用..."
echo ""
echo "后端服务: http://${1:-0.0.0.0}:8000"
echo "API文档: http://${1:-0.0.0.0}:8000/docs"
echo ""
echo "按 Ctrl+C 停止服务"
echo ""
echo "使用方法: ./start.sh [IP地址]"
echo "示例: ./start.sh 192.168.1.100"
echo "默认: ./start.sh (使用 0.0.0.0)"
echo ""

if [ -z "$1" ]; then
    echo "使用默认配置启动..."
    python3 -m backend.main
else
    echo "使用指定IP $1 启动..."
    export APP_HOST=$1
    python3 -m backend.main
fi

